package org.example.utils;

import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;

/**
 * 核心servlet
 * 执行handr或者错误处理
 */
public class CommonServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse res) throws IOException {
        try {
            Router.ME.Do(req.getRequestURI(),req,res);
        } catch (NoSuchMethodException e) {
            res.getWriter().write("err :"+e.getMessage());
        } catch (IllegalAccessException e) {
            res.getWriter().write("err :"+e.getMessage());
        } catch (InstantiationException e) {
            res.getWriter().write("err :"+e.getMessage());
        }
    }
}
